/**
 * 地址转向
 * 登录，注册，退出之后跳转的地址
 */
function toLogin(){
	//console.log(location.href+" --- url");
	location.href = "/web/login?u=" + encodeURIComponent(location.href);
	return false;
}

function toRegister(){
	location.href = "/web/register/homePage?u=" + encodeURIComponent(location.href);
	return false;
}

function toLoginOut(){
	location.href = "/web/logout?u=" + encodeURIComponent(location.href);
	return false;
}


//如果没有提供onSureCallback，则不会有确认按钮
function tipMsg(msg, title, onCloseCallback, onSureCallback){
	tipMsgRaw(msg, title, false, onCloseCallback, onSureCallback);
}

function tipErr(msg, title, onCloseCallback){
	tipMsgRaw(msg, title, true, onCloseCallback);
}

function tipMsgRaw(msg, title, isErr, onCloseCallback, onSureCallback){
	title = title == null ? "提示" : title;
	
	var html = 
	'<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">'+
	  '<div class="modal-dialog modal-sm"  id="model-tip-message">'+
	    '<div class="modal-content">'+
	    	(isErr 
	    	? '<div class="modal-header" style="background:#c9302c; color: #ffffff">' 
	    	: '<div class="modal-header">') +  /*style="background:#337ab7; color: #ffffff"*/
	        '<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>'+
	        '<h4 class="modal-title" id="myModalLabel">' + title + '</h4>'+
	      '</div>'+
	    '<div id="___modal_msg_body_div" class="modal-body">'+
	    msg +
	      '</div>'+
	      '<div class="modal-footer">'+
	      (onSureCallback != null ? '<button type="button" class="btn btn-default" data-dismiss="modal" id="___modal_sure_button">确认</button>' : '') +
	        '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'+
	      '</div>'+
	    '</div>'+
	  '</div>'+
	'</div>';
	var model = $(html);
	$("body").prepend(model);
	
	//如果有提供确认回调，就调用它
	if(onSureCallback != null){
		model.find("#___modal_sure_button").click(function(){
			onSureCallback(model.find("#___modal_msg_body_div"));
			model.modal('hide');
		});
	}
	model.modal('show');
	model.on("hidden.bs.modal", function(e){
		$(this).remove();
		
		//如果有提供callback，就回调
		if(onCloseCallback != null) onCloseCallback();
	});
}

function configWechat(data){
	var appId = data.appid;
	var timestamp = data.timestamp;
	var nonceStr = data.nonceStr;
	var signature= data.signature;
	wx.config({
		debug : false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
		appId : appId, // 必填，公众号的唯一标识
		timestamp : timestamp, // 必填，生成签名的时间戳
		nonceStr : nonceStr, // 必填，生成签名的随机串
		signature : signature,// 必填，签名，见附录1
		jsApiList : ['closeWindow']	
	});	
}